import $ from '../common';
Page({
  data: {
    idx:0,
    noimg:$.noImage
  },
  onLoad(e) {
    this.setData({
      zonecode: wx.getStorageSync('addresscode') || ''
    })
    this.getuserstudent()
  },
  onShow() {
    if(this.data.isSwitch){
      this.setData({
        user:this.data.usestudent[this.data.idx],
      })
      this.reset()
    }
  },
  onReachBottom() {//触底

  },
  reset(){
    this.setData({
      page:1,
      tip:'上滑加载更多',
      courselist:[]
    })
    this.getgroups()
  },
  getuserstudent() { //获取_用户下认证子女
    const { zonecode} = this.data
    $.get('/user/students/certified', {
      zonecode
    }, res => {
      let user = res.students[this.data.idx]
      this.setData({
        usestudent: res.students,
        user
      })
      this.getgroups()
    })
  },
  switchchildren(){//去往学员
    $.navigateTo('/address/switchchildren')
  },
  godetail(e){
    const{student_uuid}=this.data.user
    const{uuid}=e.currentTarget.dataset    
    $.navigateTo(`/course/alreadycourse?student_uuid=${student_uuid}&group_uuid=${uuid}&type=collection`)
  },
  getgroups(){//获取收藏列表
    $.get('/campus/student/favoritegroups',{
      page:this.data.page,
      limit:20,
      student_uuid:this.data.user.student_uuid,
      campus_uuid:this.data.user.campus_uuid
    },res=>{
      // this.data.page++
      // if(res.studentpaper.length<20){
      //   this.data.tip='已经到底了'
      // }else{
      //   this.data.tip='上滑加载更多'
      // }
      // this.setData({
      //   courselist:[...this.data.courselist,...res.studentpaper]
      // })
      this.setData({
        info:res
      })
    })
  },
  getcancel(e){
    const{campus_uuid,group_uuid}=e.currentTarget.dataset
    $.get('/campus/group/favor/cancel',{
      zonecode:this.data.zonecode,
      campus_uuid,
      group_uuid,
      student_uuid:this.data.user.student_uuid
    },res=>{
      this.reset()
    })
  }
})